树莓派 Ubuntu Server 20.04 LTS 初始化

修改系统时间

  1. 修改timesyncd.conf

    sudo vi /etc/systemd/timesyncd.conf
    
  2. 修改NTP参数,修改结果为:

    #  This file is part of systemd.
    #
    #  systemd is free software; you can redistribute it and/or modify it
    #  under the terms of the GNU Lesser General Public License as published by
    #  the Free Software Foundation; either version 2.1 of the License, or
    #  (at your option) any later version.
    #
    # Entries in this file show the compile time defaults.
    # You can change settings by editing this file.
    # Defaults can be restored by simply deleting this file.
    #
    # See timesyncd.conf(5) for details.
    
    [Time]
    NTP=ntp2.aliyun.com
    #FallbackNTP=ntp.ubuntu.com
    #RootDistanceMaxSec=5
    #PollIntervalMinSec=32
    #PollIntervalMaxSec=2048
    
  3. 设置

    sudo timedatectl set-timezone "Asia/Shanghai"
    sudo timedatectl set-local-rtc true
    sudo timedatectl set-ntp true
    

修改apt国内源

  1. 备份

    sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
    
  2. 修改sources.list, 文件内容为:

    deb https://mirrors.aliyun.com/ubuntu-ports focal main restricted
    deb https://mirrors.aliyun.com/ubuntu-ports focal-updates main restricted
    deb https://mirrors.aliyun.com/ubuntu-ports focal universe
    deb https://mirrors.aliyun.com/ubuntu-ports focal-updates universe
    deb https://mirrors.aliyun.com/ubuntu-ports focal multiverse
    deb https://mirrors.aliyun.com/ubuntu-ports focal-updates multiverse
    deb https://mirrors.aliyun.com/ubuntu-ports focal-backports main restricted universe multiverse
    deb https://mirrors.aliyun.com/ubuntu-ports focal-security main restricted
    deb https://mirrors.aliyun.com/ubuntu-ports focal-security universe
    deb https://mirrors.aliyun.com/ubuntu-ports focal-security multiverse
    

新增swap

  1. 创建swapfile

    sudo fallocate -l 2G /swapfile
    
  2. 修改swapfile权限

    sudo chmod 600 /swapfile
    
  3. 创建交换空间

    sudo mkswap /swapfile
    
  4. 激活swapfile

    sudo swapon /swapfile
    
  5. 永久化
    修改文件/etc/fstab,添加以下内容

    /swapfile       swap    swap    defaults        0       0
    
  6. 设置交换值

    • 查看

      cat /proc/sys/vm/swappiness
      
    • 临时生效

      sudo sysctl vm.swappiness=40
      
    • 永久生效
      /etc/sysctl.d中新建配置文件10-swappiness.conf, 内容为

       vm.swappiness=40
      
  7. 停用swap

    sudo swapoff /swapfile